<!--
* @author luguoxiang
* @date 2021-09-07
* 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
-->
<template>
  {{ $route.path }}
  <slot v-if="$route.path === url"></slot>
</template>

<script lang="ts" setup="EditContainerModal">
import { ref } from 'vue';
import { DetailContainerProps, EditContainerExpose } from './types';

export declare interface Props extends DetailContainerProps {
  /**
   * 显示模式
   */
  mode?: 'create' | 'update' | 'detail';
  url: string;
}

const emits = defineEmits(['open', 'close', 'before-close']);
const props = withDefaults(defineProps<Props>(), {
  mode: 'detail',
});

const containerRef = ref();

/**
 * 打开
 * @param params
 */
function open(params: any) {
  containerRef.value.open();
  emits('open', params);
}

/**
 * 强制关闭
 */
function forceClose() {
  containerRef.value.close();
}

/**
 * 关闭
 * @param force
 */
function close(force = false) {
  if (force) {
    forceClose();
  } else {
    emits('before-close', forceClose);
  }
}

const exposeApi: EditContainerExpose = {
  open,
  close,
  forceClose,
};
defineExpose<EditContainerExpose>(exposeApi);
</script>
